package Interact;

import java.io.*;
import Tool.*;

final public class Image implements Binaryable, Interactable{
	private String fn = "";
	
	/** 文件格式 */
	private String format = "jpeg";
	
	public Image(String _fn){
		fn = _fn;
		String[] arr = fn.split(".");
		if (arr.length > 1)
			format = arr[arr.length-1];
	}
	
	public Image(String _fn, String _format){
		this(_fn);
		format = _format;
	}
	
	public Image(InputStream in) throws IOException{
		fromBytes(in);
	}
	
	public String getFormat(){
		return format;
	}
	
	public void setFormat(String _format){
		format = _format;
	}
	
	@Override
	public void fromBytes(InputStream in) throws IOException{
		format = Tool.readString(in);
		fn = Tool.readString(in);
	}
	
	@Override
	public void toBytes(OutputStream out) throws IOException {
		Tool.writeString(format, out);
		Tool.writeString(fn, out);
	}
	
	@Override
	public void display(Interface out) throws IOException{
		out.print(String.format("<img src=\"%s\">", fn));
	}

	@Override
	public String getKey() {
		// TODO Auto-generated method stub
		return fn;
	}

	@Override
	public void setValueViaInterface(Interface inf) {
	}

	@Override
	public void setMode(int mode) {
		// TODO Auto-generated method stub
		
	}
}








